<?php

/**
 * Created by PhpStorm.
 * User: dumbledore
 * Date: 2018/2/26
 * Time: 下午2:37
 */
class Order_api extends CI_Controller
{

    public function __construct(){
        parent::__construct();
        $this->load->database();
        $this->load->library('form_validation');//加载表单验证类库
        $this->load->helper('json');
        $this->load->helper('common');
        $this->load->model('user_model');
        $this->load->model('order_model');
        $this->load->model('excel_model');
        $this->load->model('goods_model');
        $this->load->library('session');
    }

//    // 新增订单信息
//    public function add_order_info()
//    {
//        $post = $this->input->post();
//        log_message("error",json_encode($post));
//        if(check_param($post,['order_bn','shop_customer_id','money','express_fee','status','order_at','order_info','time_stamp','token']))
//        {
//            // 验签
//            $token = create_token($post,$this->config->item("token_const"));
//            $check_res = check_token($token,$post['token'],$post['time_stamp'],$this->config->item("time_out"));
//            if($check_res['status'] == -1)
//            {
//                send_json(array('code'=>-1,'data'=>'','msg'=>$check_res['msg']));
//            }
//
//            $res = $this->order_model->add_order_info($post);
//            if($res)
//            {
//                send_json(array('code'=>0,'data'=>'','msg'=>"同步成功"));
//            }else{
//                send_json(array('code'=>-1,'data'=>'','msg'=>"同步失败"));
//            }
//        }else{
//            send_json(array('code'=>-1,'data'=>'','msg'=>"缺少参数"));
//        }
//
//    }

    // 订单修改状态
    public function update_order_status()
    {
        $post = $this->input->post();
        log_message("error",json_encode($post));

        if(check_param($post,['order_bn','shop_customer_id','money','status','order_info','time_stamp','token']))
        {

            // 验签
            $token = create_token($post,$this->config->item("token_const"));
        

            $check_res = check_token($token,$post['token'],$post['time_stamp'],$this->config->item("time_out"));
           
            if($check_res['status'] == -1)
            {
                send_json(array('code'=>-1,'data'=>'','msg'=>$check_res['msg']));
            }

            $res = $this->order_model->update_order_info($post);
            
            if($res)
            {
                send_json(array('code'=>0,'data'=>'','msg'=>"同步成功"));
            }else{
                send_json(array('code'=>-1,'data'=>'','msg'=>"同步失败"));
            }
        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"缺少参数"));
        }
    }

}